﻿using System.Web;
using System.Web.SessionState;

namespace PortalCurriculo.WebUI.Helpers
{
    public static class SessionHelper
    {
        public enum SessionName
        {
            UsuarioLogado,
            Cultura,
            EmpresaLogada,
            ProfissionalLogado,
            ParceiroLogado,
            AdministradorLogado,
            SelecionadorLogado,
            RedatorLogado,
            LinksUsuario,
            EmpresasSelecionadorLogado,
            PortadorNecessidadeEspecial
        };

        public static object Session(SessionName sessionName)
        {
            return HttpContext.Current == null || HttpContext.Current.Session == null ? null : HttpContext.Current.Session[sessionName.ToString()];
        }

        public static void Session(SessionName sessionName, object value)
        {
            if (HttpContext.Current == null || HttpContext.Current.Session == null) return;

            HttpContext.Current.Session[sessionName.ToString()] = value;
        }

        public static HttpSessionState WebSession
        {
            get
            {
                return HttpContext.Current.Session;
            }
        }

        public static void ClearAllSessions()
        {
            foreach(int value in System.Enum.GetValues(typeof(SessionName)))
            {
                Session((SessionName) value, null);
            }
        }
    }
}